package manuscript.windmodelmartjan;

import repicea.stats.data.DataSet;
import repicea.stats.data.StatisticalDataException;
import repicea.stats.model.glm.GeneralizedLinearModel;
import repicea.stats.model.glm.LinkFunction.Type;
import repicea.stats.model.glm.copula.CopulaExpression;
import repicea.stats.model.glm.copula.CopulaLibrary;
import repicea.stats.model.glm.copula.FGMCopulaGLModel;

public class WindModel {

	private GeneralizedLinearModel glm;
	private FGMCopulaGLModel copulaDistanceModel;
	@SuppressWarnings("unused")
	private FGMCopulaGLModel copulaDistanceAngleModel;
	
	
	protected WindModel(String modelDefinition) {
		String filename = "C:/Users/mfortin/Publications/4-En preparation/2011 - WindThrowMartJan/data/fromSAS.csv";
		DataSet dataSet = new DataSet(filename);
		glm = new GeneralizedLinearModel(dataSet, Type.Logit, modelDefinition);
		glm.optimize();
		
		try {

//			CopulaExpression distanceCopula = new CopulaLibrary.DistanceLinkFunctionCopulaExpression(Type.Log, "plotID", "xCoordinate + yCoordinate", -.15);		// no intercept in the linear expression
//			distanceCopula.setBounds(0, new ParameterBound(null, 0d));
//			copulaDistanceModel = new FGMCopulaGLModel(glm, distanceCopula);
//			copulaDistanceModel.gridSearch(copulaDistanceModel.getParameters().m_iRows - 1, -.25d, -.15d, .01);
//			copulaDistanceModel.optimize();

			
			CopulaExpression distanceAngleCopula = new CopulaLibrary.DistanceAndAngleFunctionCopulaExpression("plotID", "xCoordinate + yCoordinate", -.15, Math.PI / 2);
			copulaDistanceModel = new FGMCopulaGLModel(glm, distanceAngleCopula);
//			copulaDistanceModel.gridSearch(copulaDistanceModel.getParameters().m_iRows - 1, -.25d, -.15d, .01);
			copulaDistanceModel.optimize();
			
			
			
			
			glm.getSummary();
//			copulaSimpleModel.getSummary();
			copulaDistanceModel.getSummary();

			
			
		} catch (StatisticalDataException e) {
			e.printStackTrace();
		}
	}
	
	
	@SuppressWarnings("unused")
	public static void main(String args[]) {
		String simpleDefinition = "response ~ HD_ratio + HD_ratio:speciesGroup";
		WindModel example1 = new WindModel(simpleDefinition);
		int u = 0;
	}

	
	
	
	
}
